package com.dgut.service.serviceImpl;

import com.dgut.dao.RoleDao;
import com.dgut.pojo.Role;
import com.dgut.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@CacheConfig(cacheNames = "roleCache")
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleDao roleDao;

    @Override
    @Cacheable(key = "#root.args[0]")
    public List<Role> findAllById(Long id) {
        return roleDao.findAllById(id);
    }

    @Override
    @CacheEvict(value = "roleCache",allEntries = true)
    public void saveRole(Role role) {
        roleDao.save(role);
    }

}
